#include <cstdio>
#include <algorithm>
#include <cstring>
#define MAX 15
using namespace std;
int main() {
	int n,dp[MAX*400+1],V[MAX],sum,dif;;
	
	while(scanf("%d",&n)&&n) {
		sum = 0;
		for(int i=0;i<n;i++) {
			scanf("%d",V+i);
			sum+=V[i];
		}
		memset(dp,0,sizeof(dp));
		for(int i=0;i<n;i++)
			for(int j=sum/2;j>=0;j--)
				if(j>=V[i]&&dp[j]<dp[j-V[i]]+V[i])
					dp[j]=dp[j-V[i]]+V[i];
		dif = sum-2*dp[sum/2];
		printf("%d\n",dif);
	}
	return 0;
}

